/**
 *
 * @param useDebounce 防抖函数
 * @param callback 方法
 * @param delay  时间
 * @returns
 */
export const useDebounce = (callback: any, delay: any) => {
  let timeout: any
  return function debounced(...args: any) {
    clearTimeout(timeout)
    timeout = setTimeout(() => {
      callback(...args)
    }, delay)
  }
}
/**
 *
 * @param useThrottle 节流函数
 * @param callback 方法
 * @param delay  时间
 * @returns
 */
export const useThrottle = (callback: any, delay: any) => {
  let lastExecutionTime = 0
  return function throttled(...args: any) {
    const now = new Date().getTime()
    if (now - lastExecutionTime >= delay) {
      callback(...args)
      lastExecutionTime = now
    }
  }
}
